﻿using AutoMapper;
using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyWrite.API.Appicant.Command.QingJia;
using MediatR;

namespace B.S.DataBase.MyWrite.API.Appicant.CommandHandler.QingJia
{
    public class QingJiaUdpCommandHandler : IRequestHandler<QingJiaUdpCommand, APIResult<object>>
    {
        private readonly IBaseRepository<LeaveApplicationForm> lRepo;
        private readonly IMapper mapper;

        public QingJiaUdpCommandHandler(IBaseRepository<LeaveApplicationForm>lRepo,IMapper mapper)
        {
            this.lRepo = lRepo;
            this.mapper = mapper;
        }


        public async Task<APIResult<object>> Handle(QingJiaUdpCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            result.Code = APIEnum.修改成功;
            result.Msg = APIEnum.修改成功.ToString();
            var list = lRepo.GetAll().Result.Where(x => x.FormId == request.FormId).FirstOrDefault();
            list.UserName = request.UserName;
            list.DepartId = request.DepartId;
            list.LeaveCategory = request.LeaveCategory;
            list.BeginTime = request.BeginTime;
            list.EndTime = request.EndTime;
            list.BaoDaoTime = request.BaoDaoTime;
            list.LeaveReason = request.LeaveReason;
            list.DepartName = request.DepartName;
            list.Zongtime = request.Zongtime;
            await lRepo.Update(list);   
            return await Task.FromResult(result);   

        }
    }
}
